package timing.ukulele.common.data;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public interface BaseDataConverter<P, V> {
    P v2p(V v);

    V p2v(P p);

    default List<P> v2pList(List<V> list) {
        if (CollectionUtils.isEmpty(list))
            return new ArrayList<>(0);
        List<P> pList = new ArrayList<>(list.size());
        list.forEach(v -> {
            pList.add(v2p(v));
        });
        return pList;
    }

    default List<V> p2vList(List<P> list) {
        if (CollectionUtils.isEmpty(list))
            return new ArrayList<>(0);
        List<V> pList = new ArrayList<>(list.size());
        list.forEach(p -> {
            pList.add(p2v(p));
        });
        return pList;
    }
}
